package com.yuyue.dronesystem.entities;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.yuyue.dronesystem.enums.LoginType;

/**
 * UserLogin
 */
@Entity
@Table(name = "user_login")
public class UserLogin {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "login_id")
    private Long loginId;
    @Column(name = "login_type")
    @Enumerated(EnumType.STRING)
    private LoginType loginType;
    @Column(name = "identifier")
    private String identifier;
    @Column(name = "credential")
    private String credential;

    @ManyToOne(targetEntity = UserInfo.class)
    @JoinColumn(name = "user_id", referencedColumnName = "user_id")
    private UserInfo userInfo;

    public UserLogin() {
    }

    public UserLogin(Long loginId, LoginType loginType, String identifier, String credential) {
        this.loginId = loginId;
        this.loginType = loginType;
        this.identifier = identifier;
        this.credential = credential;
    }

    public Long getLoginId() {
        return this.loginId;
    }

    public void setLoginId(Long loginId) {
        this.loginId = loginId;
    }

    public LoginType getLoginType() {
        return this.loginType;
    }

    public void setLoginType(LoginType loginType) {
        this.loginType = loginType;
    }

    public String getIdentifier() {
        return this.identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getCredential() {
        return this.credential;
    }

    public void setCredential(String credential) {
        this.credential = credential;
    }

    /**
     * @return the userInfo
     */
    public UserInfo getUserInfo() {
        return userInfo;
    }

    /**
     * @param userInfo the userInfo to set
     */
    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public UserLogin loginId(Long loginId) {
        this.loginId = loginId;
        return this;
    }

    public UserLogin loginType(LoginType loginType) {
        this.loginType = loginType;
        return this;
    }

    public UserLogin identifier(String identifier) {
        this.identifier = identifier;
        return this;
    }

    public UserLogin credential(String credential) {
        this.credential = credential;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this)
            return true;
        if (!(o instanceof UserLogin)) {
            return false;
        }
        UserLogin userLogin = (UserLogin) o;
        return Objects.equals(loginId, userLogin.loginId) && Objects.equals(loginType, userLogin.loginType) && Objects.equals(identifier, userLogin.identifier) && Objects.equals(credential, userLogin.credential);
    }

    @Override
    public int hashCode() {
        return Objects.hash(loginId, loginType, identifier, credential);
    }

    @Override
    public String toString() {
        return "{" +
            " loginId='" + getLoginId() + "'" +
            ", loginType='" + getLoginType() + "'" +
            ", identifier='" + getIdentifier() + "'" +
            ", credential='" + getCredential() + "'" +
            "}";
    }
}